package com.cleaningcloud.cld.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import com.cleaningcloud.common.security.annotation.RequiresPermissions;
import com.cleaningcloud.cld.domain.CldContract;
import com.cleaningcloud.cld.service.ICldContractService;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.utils.poi.ExcelUtil;
import com.cleaningcloud.common.core.web.page.TableDataInfo;

/**
 * 合同Controller
 * 
 * @author cleaningcloud
 * @date 2024-10-06
 */
@RestController
@RequestMapping("/contract")
public class CldContractController extends BaseController
{
    @Autowired
    private ICldContractService cldContractService;

    /**
     * 查询合同列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CldContract cldContract)
    {
        startPage();
        List<CldContract> list = cldContractService.selectCldContractList(cldContract);
        return getDataTable(list);
    }

    /**
     * 导出合同列表
     */
    @Log(title = "合同", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CldContract cldContract)
    {
        List<CldContract> list = cldContractService.selectCldContractList(cldContract);
        ExcelUtil<CldContract> util = new ExcelUtil<CldContract>(CldContract.class);
        util.exportExcel(response, list, "合同数据");
    }

    /**
     * 获取合同详细信息
     */
    @GetMapping(value = "/{contractId}")
    public AjaxResult getInfo(@PathVariable("contractId") Long contractId)
    {
        return success(cldContractService.selectCldContractByContractId(contractId));
    }

    /**
     * 根据项目ID合同详细信息
     */
    @GetMapping(value = "/getInfoProject/{projectId}")
    public AjaxResult getInfoProject(@PathVariable("projectId") Long projectId)
    {
        return success(cldContractService.selectCldContractByProjectId(projectId));
    }

    /**
     * 新增合同
     */
    @Log(title = "合同", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CldContract cldContract)
    {
        return toAjax(cldContractService.insertCldContract(cldContract));
    }

    /**
     * 修改合同
     */
    @Log(title = "合同", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CldContract cldContract)
    {
        return toAjax(cldContractService.updateCldContract(cldContract));
    }

    /**
     * 删除合同
     */
    @Log(title = "合同", businessType = BusinessType.DELETE)
	@DeleteMapping("/{contractIds}")
    public AjaxResult remove(@PathVariable Long[] contractIds)
    {
        return toAjax(cldContractService.deleteCldContractByContractIds(contractIds));
    }
}
